cd "C:\DRS\"

***************************************************
*** Figure 2 ***
use PanelFundsDatabase.dta, clear

log using F2.log, replace
** Panel A **
* No. of Funds
tab year if fundtype2 == "Global"
tab year if fundtype2 == "Specialized"

* Assets under management
qui bys year : egen naglobal = sum(netassets)  if  fundtype2 == "Global"
qui bys year : egen naspec = sum(netassets)  if  fundtype2 == "Specialized"
tabstat  naglobal naspec, by (year)  stats (max)

** Panel B **
* Median No. of Holdings: All Funds
tabstat nosec if fundtype7 == "World", stats(p50) by(year)
tabstat forholdings if fundtype7 == "World" & year > 1996, stats(p50) by(year)
tabstat nosec if fundtype7 == "Foreign", stats(p50) by(year)
tabstat nosec if fundtype7 == "Emerging Market", stats(p50) by(year)
tabstat nosec if fundtype2 == "Specialized", stats(p50) by(year)

** Panel C **
* Median No. of Holdings: Specialized Funds
tabstat nosec if fundtype7 == "Asia", stats(p50) by(year)
tabstat nosec if fundtype7 == "Europe", stats(p50) by(year)
tabstat nosec if fundtype7 == "Latin America", stats(p50) by(year)
tabstat nosec if fundtype7 == "Country Fund", stats(p50) by(year)
log close
***************************************************

***************************************************
*** Table 1 ***
use PanelFundsDatabase.dta, clear

log using T1.log, replace
** Top Panel **
tabstat forholdings if fundtype2 == "Global", stats(mean p50 sd)
tabstat nosec if fundtype7 == "World", stats(mean p50 sd)
tabstat forholdings if fundtype7 == "World" , stats(mean p50 sd)
tabstat forholdings if fundtype7 == "Foreign" , stats(mean p50 sd)
tabstat nosec if fundtype7 == "Emerging Market"|fundtype7 == "Asia"|fundtype7 == "Europe"|fundtype7 == "Latin America", stats(mean p50 sd)
tabstat nosec if fundtype7 == "Emerging Market", stats(mean p50 sd)
tabstat nosec if fundtype7 == "Asia", stats(mean p50 sd)
tabstat nosec if fundtype7 == "Europe", stats(mean p50 sd)
tabstat nosec if fundtype7 == "Latin America", stats(mean p50 sd)
tabstat nosec if fundtype7 == "Country Fund", stats(mean p50 sd)
tabstat nosec, stats(mean p50 sd)

** Bottom Panel **
* Median No. of Holdings by MF Family
tabstat nosec, stats(median) by(gfamily)

* Calculating Stats by Quintile
preserve
collapse (p50) nosec, by(gfamily)
sort nosec
gen x =1 
egen y = sum(x)
gen q1_th = (y+1)/5
gen q2_th = 2*(y+1)/5
gen q3_th = 3*(y+1)/5
gen q4_th = 4*(y+1)/5
gen n = _n
tabstat nosec if n <= q1_th, stats(mean max)
tabstat nosec if n > q1_th & n <=q2_th, stats(mean max)
tabstat nosec if n > q2_th & n <=q3_th, stats(mean max)
tabstat nosec if n > q3_th & n <=q4_th, stats(mean max)
tabstat nosec if n > q4_th, stats(mean max)
restore
log close
***************************************************

***************************************************
*** Table 7 ***
use PanelFundsDatabase.dta, clear
drop if year < 1997

tabulate family, gen(f)
tabulate year, gen(y)
gen global = 0
replace global = 1 if fundtype2 == "Global"
gen specialized = 0
replace specialized = 1 if fundtype2 == "Specialized"

reg nosec y1-y9, robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using T7_top.xls, replace lab  adds(Adjusted,`adjusted')
reg nosec global specialized, robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using T7_top.xls, append lab  adds(Adjusted,`adjusted')
reg nosec f1-f433  , robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using T7_top.xls, append lab  adds(Adjusted,`adjusted')
reg nosec global specialized y1-y9 f1-f433, robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using T7_top.xls, append lab  adds(Adjusted,`adjusted')

bys family year: egen agexp = sum(expenses)
bys family year: egen agna = sum(netassets)
replace agna= agna/1000

reg nosec nomanagers mngtenure fundage global specialized y1-y9, robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using T7_bottom.xls, replace lab  keep(nomanagers mngtenure fundage)  adds(Adjusted,`adjusted')
reg nosec nomanagers mngtenure fundage agexp agna global specialized y1-y9, robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using T7_bottom.xls, append lab  keep(nomanagers mngtenure fundage agexp agna) adds(Adjusted,`adjusted')
reg nosec nomanagers mngtenure fundage global specialized y1-y9 f1-f433  , robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using T7_bottom.xls, append lab keep(nomanagers mngtenure fundage) adds(Adjusted,`adjusted')
reg nosec nomanagers mngtenure fundage agexp agna global specialized y1-y9 f1-f433  , robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using T7_bottom.xls, append lab keep(nomanagers mngtenure fundage agexp agna) adds(Adjusted,`adjusted')

keep if top10 > 0
keep if top10 < 100

reg top10 y1-y9, robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using T7_top.xls, append lab  adds(Adjusted,`adjusted')
reg top10 global specialized, robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using T7_top.xls, append lab  adds(Adjusted,`adjusted')
reg top10 f1-f433  , robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using T7_top.xls, append lab  adds(Adjusted,`adjusted')
reg top10 global specialized y1-y9 f1-f433, robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using T7_top.xls, append lab  adds(Adjusted,`adjusted')

reg top10 nomanagers mngtenure fundage global specialized y1-y9, robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using T7_bottom.xls, append lab keep(nomanagers mngtenure fundage) adds(Adjusted,`adjusted')
reg top10 nomanagers mngtenure fundage agexp agna global specialized y1-y9, robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using T7_bottom.xls, append lab keep(nomanagers mngtenure fundage agexp agna) adds(Adjusted,`adjusted')
reg top10 nomanagers mngtenure fundage global specialized y1-y9 f1-f433  , robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using T7_bottom.xls, append lab keep(nomanagers mngtenure fundage) adds(Adjusted,`adjusted')
reg top10 nomanagers mngtenure fundage agexp agna global specialized y1-y9 f1-f433  , robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using T7_bottom.xls, append lab keep(nomanagers mngtenure fundage agexp agna) adds(Adjusted,`adjusted')
***************************************************

***************************************************
*** Appendix Table 7 ***
use PanelFundsDatabase.dta, clear
tabulate nomanagers, gen (nm)

reg nosec nm1-nm7 , robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using AT7.xls, replace lab adds(Adjusted,`adjusted')

keep if top10 > 0
keep if top10 < 100

reg top10 nm1-nm7 , robust h cluster(family)
local adjusted = e(r2_a)
outreg2 using AT7.xls, append lab  adds(Adjusted,`adjusted')
***************************************************



